<template>
  <view class="job-card" v-for="item in 3" :key="item">
    <!-- 头部 -->
    <view class="job-card__head">
      <view class="skeleton skeleton-title" v-if="loading"></view>
      <view class="job-card__title" v-else>
        {{ title }}
        <span class="badge badge--hot" v-if="isHot">急聘</span>
        <span class="badge" v-if="isDispatch">派遣</span>
      </view>

      <view class="skeleton skeleton-salary" v-if="loading"></view>
      <view class="job-card__salary" v-else>{{ salary }}</view>
    </view>

    <!-- meta信息 -->
    <view class="job-card__meta" v-if="!loading">
      <span>{{ company }}</span>
      <span>{{ people }}</span>
      <span>{{ financing }}</span>
    </view>
    <view class="job-card__meta" v-else>
      <view class="skeleton skeleton-meta" v-for="i in 3" :key="i"></view>
    </view>

    <!-- 标签 -->
    <view class="job-card__tags" v-if="!loading">
      <view class="tag" v-for="(item, i) in tags" :key="i">{{ item }}</view>
    </view>
    <view class="job-card__tags" v-else>
      <view class="skeleton skeleton-tag" v-for="i in 4" :key="i"></view>
    </view>

    <!-- 底部 -->
    <view class="job-card__foot">
      <view class="author">
        <view v-if="loading" class="skeleton skeleton-avatar"></view>
        <image v-else class="author__avatar" :src="avatar" alt="" />
        <view class="author__info">
          <view class="skeleton skeleton-name" v-if="loading"></view>
          <view v-else class="author__name">{{ author }}</view>

          <view class="skeleton skeleton-role" v-if="loading"></view>
          <view v-else class="author__role">{{ role }}</view>
        </view>
      </view>

      <view v-if="loading" class="skeleton skeleton-loc"></view>
      <view v-else class="job-card__loc">{{ location }}</view>
    </view>
  </view>
</template>

<script setup lang="ts">
defineProps({
  loading: { type: Boolean, default: true },
  title: { type: String, default: '' },
  salary: { type: String, default: '' },
  company: { type: String, default: '' },
  people: { type: String, default: '' },
  financing: { type: String, default: '' },
  tags: { type: Array<string>, default: () => [] },
  author: { type: String, default: '' },
  role: { type: String, default: '' },
  avatar: { type: String, default: '' },
  location: { type: String, default: '' },
  isHot: { type: Boolean, default: false },
  isDispatch: { type: Boolean, default: false }
});
</script>

<style lang="scss" scoped>
.job-card {
  position: relative;
  padding: 14px;
  margin-left: 15px;
  width: calc(100vw - 30px);
  border-radius: 16rpx;
  background-color: #fff;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
  margin-top: 20px;

  &__head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12rpx;
  }

  &__title {
    flex: 1;
    font-size: 32rpx;
    font-weight: bold;
    color: #333;

    .badge {
      margin-left: 10rpx;
      padding: 4rpx 10rpx;
      font-size: 22rpx;
      border-radius: 8rpx;
      color: #5b6577;
      background: #f2f4f7;
    }

    .badge--hot {
      color: #fff;
      background: #ff5a57;
    }
  }

  &__salary {
    color: #2ecc71;
    font-weight: 600;
    font-size: 32rpx;
    white-space: nowrap;
  }

  &__meta {
    margin-top: 16rpx;
    display: flex;
    flex-wrap: wrap;
    gap: 16rpx;
    font-size: 24rpx;
    color: #888;
  }

  &__tags {
    margin-top: 16rpx;
    display: flex;
    flex-wrap: wrap;
    gap: 12rpx;

    .tag {
      padding: 8rpx 16rpx;
      border-radius: 8rpx;
      background: #f5f7fa;
      color: #666;
      font-size: 22rpx;
    }
  }

  &__foot {
    margin-top: 20rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16rpx;

    .author {
      display: flex;
      align-items: center;
      gap: 16rpx;

      &__avatar {
        width: 60rpx;
        height: 60rpx;
        border-radius: 50%;
      }

      &__info {
        line-height: 1.4;

        .author__name {
          font-size: 26rpx;
          color: #222;
          font-weight: 600;
        }

        .author__role {
          font-size: 22rpx;
          color: #888;
        }
      }
    }

    .job-card__loc {
      font-size: 22rpx;
      color: #888;
    }
  }
}

/* 骨架屏基础样式 */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #f9f9f9 37%, #f0f0f0 63%);
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
  border-radius: 8rpx;
}

/* 骨架屏各部分尺寸 */
.skeleton-title {
  width: 60%;
  height: 40rpx;
}

.skeleton-salary {
  width: 100rpx;
  height: 40rpx;
}

.skeleton-meta {
  width: 140rpx;
  height: 30rpx;
}

.skeleton-tag {
  width: 100rpx;
  height: 36rpx;
  border-radius: 12rpx;
}

.skeleton-avatar {
  width: 60rpx;
  height: 60rpx;
  border-radius: 50%;
}

.skeleton-name {
  width: 100rpx;
  height: 28rpx;
}

.skeleton-role {
  width: 120rpx;
  height: 24rpx;
  margin-top: 6rpx;
}

.skeleton-loc {
  width: 140rpx;
  height: 28rpx;
}

/* 动画效果 */
@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

</style>
